from django.shortcuts import render
from rest_framework import mixins

# Create your views here.


# 老板 或者hr 在公司发布新职位
from rest_framework.views import APIView
from rest_framework.viewsets import GenericViewSet

from company.models import Job
from company.serializers import AddPositionSerializer, CompanySerializer
from userinfo.models import User, Company
from userinfo.serialziers import UserSerializer, UpdatePositionSerializer
from utils.common.base_response import APIResponse


class AddPositionView(APIView):
    def post(self, request):
        serializer = AddPositionSerializer(data=request.data)
        if serializer.is_valid():
            Job.objects.create(**serializer.validated_data)
            return APIResponse(data=serializer.data, msg='发布成功')
        else:
            return APIResponse(msg=serializer.errors)


from rest_framework.viewsets import ModelViewSet


# 修改用户 为公司 HR身份
class UpdatePositionView(mixins.UpdateModelMixin, mixins.ListModelMixin, GenericViewSet):
    serializer_class = UpdatePositionSerializer
    queryset = User.objects.all()


# 公司列表
class CompanyListView(ModelViewSet):
    serializer_class = CompanySerializer
    queryset = Company.objects.all()


